using FytSoa.Domain.Core.Result;
using FytSoa.Generator;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace FytSoa.ApiService.Controllers
{
    /// <summary>
    /// 代码生成
    /// </summary>
    public class GeneratorController : ApiController
    {
        private readonly IGeneratorService _generatorService;
        public GeneratorController(IGeneratorService generatorService)
        {
            _generatorService = generatorService;
        }
        
        [HttpGet("table")]
        public ApiResult<PageResult<DbTableInfo>> GetTable()
        {
            return JResult<PageResult<DbTableInfo>>.Success(new PageResult<DbTableInfo>()
            {
                Items = _generatorService.InitTable().Data
            });
        }
        
        [HttpGet("column")]
        public ApiResult<PageResult<DbColumnInfo>> GetTableColumn(string tableName)
        {
            return JResult<PageResult<DbColumnInfo>>.Success(new PageResult<DbColumnInfo>()
            {
                Items =_generatorService.GetColumn(tableName).Data
            });
        }
        
        [HttpPost]
        public ApiResult<string> Post([FromBody]GeneratorTableDto param)
        {
            return  _generatorService.CreateCode(param);
        }
    }
}